[?php

/**
 * <?php echo $this->getModuleName() ?> module configuration.
 *
 * @package    ##PROJECT_NAME##
 * @subpackage <?php echo $this->getModuleName()."\n" ?>
 * @author     ##AUTHOR_NAME##
 * @version    SVN: $Id: helper.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class Base<?php echo ucfirst($this->getModuleName()) ?>GeneratorHelper extends sfModelGeneratorHelper
{
  public function getUrlForAction($action)
  {
    return 'list' == $action ? '<?php echo $this->params['route_prefix'] ?>' : '<?php echo $this->params['route_prefix'] ?>_'.$action;
  }
  
  public function linkToNew($params)
  {
    $id = rand(111111,999999);
    $icon = isset($params['icon']) ? '<i class="icon-'.$params['icon'].'"></i>&nbsp;' : '';
    $size = isset($params['size']) ? ' btn-'.$params['size'] : '';
    $style = isset($params['style']) ? ' btn-'.$params['style'] : '';
    $hint = isset($params['hint']) ? '<script>$(function(){ $("#'.$id.'").tooltip({ title: "'.$params['hint'].'" }); });</script>' : '';
    if(isset($params['icon-only']) && $params['icon-only'] == true) {
        return link_to('&nbsp;'.$icon, '@'.$this->getUrlForAction('new'), array('class' => 'btn'.$size.$style, 'id' => $id)).$hint;
    } else {
        return link_to($icon.__($params['label'], array(), 'sf_admin'), '@'.$this->getUrlForAction('new'), array('class' => 'btn'.$size.$style, 'id' => $id)).$hint;
    }
  }

  public function linkToEdit($object, $params)
  {
    $id = rand(111111,999999);
    $icon = isset($params['icon']) ? '<i class="icon-'.$params['icon'].'"></i>&nbsp;' : '';
    $size = isset($params['size']) ? ' btn-'.$params['size'] : '';
    $style = isset($params['style']) ? ' btn-'.$params['style'] : '';
    $hint = isset($params['hint']) ? '<script>$(function(){ $("#'.$id.'").tooltip({ title: "'.$params['hint'].'" }); });</script>' : '';
    if(isset($params['icon-only']) && $params['icon-only'] == true) {
        return link_to('&nbsp;'.$icon, $this->getUrlForAction('edit'), $object, array('class' => 'btn'.$size.$style, 'id' => $id)).$hint;
    } else {
        return link_to($icon.__($params['label'], array(), 'sf_admin'), $this->getUrlForAction('edit'), $object, array('class' => 'btn'.$size.$style, 'id' => $id)).$hint;
    }
  }

  public function linkToDelete($object, $params)
  {
    if ($object->isNew())
    {
      return '';
    }

    $id = rand(111111,999999);
    $icon = isset($params['icon']) ? '<i class="icon-'.$params['icon'].'"></i>&nbsp;' : '';
    $size = isset($params['size']) ? ' btn-'.$params['size'] : '';
    $style = isset($params['style']) ? ' btn-'.$params['style'] : '';
    $hint = isset($params['hint']) ? '<script>$(function(){ $("#'.$id.'").tooltip({ title: "'.$params['hint'].'" }); });</script>' : '';
    if(isset($params['icon-only']) && $params['icon-only'] == true) {
        $link = link_to('&nbsp;'.$icon, $this->getUrlForAction('delete'), $object, array('class' => 'btn'.$size.$style, 'id' => $id, 'method' => 'delete', 'confirm' => !empty($params['confirm']) ? __($params['confirm'], array(), 'sf_admin') : $params['confirm'])).$hint;
    } else {
        $link = link_to($icon.__($params['label'], array(), 'sf_admin'), $this->getUrlForAction('delete'), $object, array('class' => 'btn'.$size.$style, 'id' => $id, 'method' => 'delete', 'confirm' => !empty($params['confirm']) ? __($params['confirm'], array(), 'sf_admin') : $params['confirm'])).$hint;
    }
    if($link != '') {
        $link = str_replace('f.submit()', '$.post(this.href, $(f).serialize(), function(data, status) {if(status == \'success\') { if(data != \'Error\') { $(\'.sf_admin_list\').html(data); deleteSuccess(data); } else { deleteError(data); }}}, \'html\');', $link);
    }
    return $link;
  }

  public function linkToList($params)
  {
    $id = rand(111111,999999);
    $icon = isset($params['icon']) ? '<i class="icon-'.$params['icon'].'"></i>&nbsp;' : '';
    $size = isset($params['size']) ? ' btn-'.$params['size'] : '';
    $style = isset($params['style']) ? ' btn-'.$params['style'] : '';
    $hint = isset($params['hint']) ? '<script>$(function(){ $("#'.$id.'").tooltip({ title: "'.$params['hint'].'" }); });</script>' : '';
    if(isset($params['icon-only']) && $params['icon-only'] == true) {
        return link_to('&nbsp;'.$icon, '@'.$this->getUrlForAction('list'), array('class' => 'btn'.$size.$style, 'id' => $id)).$hint;
    } else {
        return link_to($icon.__($params['label'], array(), 'sf_admin'), '@'.$this->getUrlForAction('list'), array('class' => 'btn'.$size.$style, 'id' => $id)).$hint;
    }
  }

  public function linkToSave($object, $params)
  {
    $id = rand(111111,999999);
    $icon = isset($params['icon']) ? '<i class="icon-'.$params['icon'].'"></i>&nbsp;' : '';
    $size = isset($params['size']) ? ' btn-'.$params['size'] : '';
    $style = isset($params['style']) ? ' btn-'.$params['style'] : '';
    $hint = isset($params['hint']) ? '<script>$(function(){ $("#'.$id.'").tooltip({ title: "'.$params['hint'].'" }); });</script>' : '';
    if(isset($params['icon-only']) && $params['icon-only'] == true) {
        return '<button id='.$id.' type="submit" class="btn '.$size.$style.'">&nbsp;'.$icon.'</button>'.$hint;
    } else {
        return '<button id='.$id.' type="submit" class="btn '.$size.$style.'">'.$icon.__($params['label'], array(), 'sf_admin').'</button>'.$hint;
    }
  }

  public function linkToSaveAndAdd($object, $params)
  {
    if (!$object->isNew())
    {
      return '';
    }

    $id = rand(111111,999999);
    $icon = isset($params['icon']) ? '<i class="icon-'.$params['icon'].'"></i>&nbsp;' : '';
    $size = isset($params['size']) ? ' btn-'.$params['size'] : '';
    $style = isset($params['style']) ? ' btn-'.$params['style'] : '';
    $hint = isset($params['hint']) ? '<script>$(function(){ $("#'.$id.'").tooltip({ title: "'.$params['hint'].'" }); });</script>' : '';
    if(isset($params['icon-only']) && $params['icon-only'] == true) {
        return '<button id='.$id.' type="submit" class="btn '.$size.$style.'" name="_save_and_add">&nbsp;'.$icon.'</button>'.$hint;
    } else {
        return '<button id='.$id.' type="submit" class="btn '.$size.$style.'" name="_save_and_add">'.$icon.__($params['label'], array(), 'sf_admin').'</button>'.$hint;
    }
  }
  
}
